home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d7 / laser.arc / PLAYER.C < prev    next >
C/C++ Source or Header  |  1992-01-14  |  4KB  |  201 lines

  1. /* player.c
  2.  *
  3.  * Laser Disk Access Program
  4.  * runs on the pc that supports the laser disk
  5.  * by Patrick L. McGillan
  6.  *    University of Wisconsin - Superior
  7.  *
  8.  * with special thanks to Paul McGinnis, AST Research, Inc.
  9.  * whose programs on compuserve inspired these programs
  10.  *
  11.  */
  12.  
  13.  
  14. #include "netwrk.h"
  15.  
  16.  
  17. main()
  18. {
  19.   int done;
  20.   char *fname;
  21.   char far * user_name;
  22.  
  23.   clrscr();
  24.  
  25.   system ("p:public\\netbios");
  26.  
  27.   block = (NCB far *) malloc(sizeof(NCB));
  28.   buf1 = (char far *) malloc(512);
  29.   buf2 = (char far *) malloc(512);
  30.   message = (char far *) malloc(80);
  31.  
  32.   printf ("\n\nLaser Disk Access Program");
  33.   printf ("\nby Patrick L. McGillan");
  34.   printf ("\n   University of Wisconsin - Superior");
  35.   printf ("\n\nGenerating Network Laser Disk entry . . .");
  36.   make_user();
  37.  
  38.   while (1)
  39.   {
  40.     printf ("\n\nWaiting for a user to call . . .");
  41.  
  42.     listen();
  43.  
  44.     get_fnam();
  45.  
  46.     printf ("\nMessage Received");
  47.     printf ("\nFrom User: <%Fs>", block->NCB_CALLNAME);
  48.     printf ("\nWants file name: %Fs", message);
  49.  
  50.     strcpy (fname, message);
  51.  
  52.     if (chk_fname(fname))
  53.       send_file(fname);
  54.  
  55.     hang_up();
  56.   }
  57. }
  58.  
  59.  
  60.  
  61. make_user()
  62. {
  63.   unsigned char ret_code;
  64.  
  65.   block -> NCB_COMMAND = ADD_NAME_WAIT;   /* Use default time-out values */
  66.   block -> NCB_LANA_NUM = 0;
  67.   block -> NCB_STO = 0;
  68.   block -> NCB_RTO = 0;
  69.   strncpy(block -> NCB_NAME, "Laser Disk", 16);  /* Copy name to NCB   */
  70.   strncpy(block -> NCB_CALLNAME, "*", 16);  /* Check all names on net  */
  71.   _ES = FP_SEG(block);
  72.   _BX = FP_OFF(block);
  73.   _AX = 0x100;
  74.   geninterrupt(0x5c);
  75.   ret_code = _AL;
  76.   if ((ret_code) && (ret_code != 0x0d))
  77.   {
  78.     printf("Bad return code = %02Xh\n", ret_code);
  79.     exit (1);
  80.   }
  81. }
  82.  
  83.  
  84.  
  85. listen()
  86. {
  87.   unsigned char ret_code;
  88.  
  89.   strncpy(block -> NCB_NAME, "Laser Disk", 16);  /* Copy name to NCB   */
  90.   strncpy(block -> NCB_CALLNAME, "*", 16);  /* Check all names on net  */
  91.   block -> NCB_RTO = 0;
  92.   block -> NCB_COMMAND = LISTEN_WAIT;
  93.   _ES = FP_SEG(block);
  94.   _BX = FP_OFF(block);
  95.   _AX = 0x100;
  96.   geninterrupt(0x5c);
  97.   ret_code = _AL;
  98.   if (ret_code)
  99.     printf("Error number = %02Xh\n", ret_code);
  100. }
  101.  
  102.  
  103.  
  104. get_fnam()
  105. {
  106.   unsigned char ret_code;
  107.  
  108.   block -> NCB_RTO = 0;
  109.   block -> NCB_BUFFER_OFFSET = FP_OFF(message);
  110.   block -> NCB_BUFFER_SEGMENT = FP_SEG(message);
  111.   block -> NCB_LENGTH = 80;
  112.   block -> NCB_COMMAND = RECEIVE_WAIT;
  113.   _ES = FP_SEG(block);
  114.   _BX = FP_OFF(block);
  115.   _AX = 0x100;
  116.   geninterrupt(0x5c);
  117.   ret_code = _AL;
  118.   pokeb(FP_SEG(message), FP_OFF(message) + block -> NCB_LENGTH, 0);
  119.   if (ret_code)
  120.     printf("Error number = %02Xh\n", ret_code);
  121. }
  122.  
  123.  
  124.  
  125. send(buf)
  126. char far * buf;
  127. {
  128.   unsigned char ret_code;
  129.  
  130.   block -> NCB_STO = 0;
  131.   block -> NCB_BUFFER_OFFSET = FP_OFF(buf);
  132.   block -> NCB_BUFFER_SEGMENT = FP_SEG(buf);
  133.   block -> NCB_LENGTH = bytes;
  134.   block -> NCB_COMMAND = SEND_WAIT;
  135.   _ES = FP_SEG(block);
  136.   _BX = FP_OFF(block);
  137.   _AX = 0x100;
  138.   geninterrupt(0x5c);
  139.   ret_code = _AL;
  140.   return (ret_code);
  141. }
  142.  
  143.  
  144.  
  145. chk_fname(fname)
  146. char *fname;
  147. {
  148.   int done;
  149.   struct ffblk file;
  150.  
  151.   done = findfirst (fname, &file, 0x3f);
  152.  
  153.   return (!done);
  154. }
  155.  
  156.  
  157.  
  158. send_file(fname)
  159. char *fname;
  160. {
  161.   int disk;
  162.  
  163.   disk = fopen (fname, "r+b");
  164.   printf ("\nSending File: %s", fname);
  165.  
  166.   while (1)
  167.   {
  168.     bytes = fread (buf1, 1, 512, disk);
  169.     if (bytes < 0) { hang_up(); return; }
  170.     if (send(buf1)) { hang_up(); return; }
  171.     if (bytes == 0) { fclose(disk); hang_up(); return; }
  172.     bytes = fread (buf2, 1, 512, disk);
  173.     if (wait()) { hang_up(); return; }
  174.     if (send(buf2)) { hang_up(); return; }
  175.     if (wait()) { hang_up(); return; }
  176.     if (bytes == 0) { fclose(disk); hang_up(); return; }
  177.   }
  178. }
  179.  
  180.  
  181. wait()
  182. {
  183.     byte done;
  184.  
  185.     do
  186.       done = block->NCB_CMD_CPLT;
  187.     while (done == 0xff);
  188. }
  189.  
  190.  
  191. hang_up()
  192. {
  193.   printf ("\nHanging up connection");
  194.   block -> NCB_COMMAND = HANG_UP_WAIT;
  195.   _ES = FP_SEG(block);
  196.   _BX = FP_OFF(block);
  197.   _AX = 0x100;
  198.   geninterrupt(0x5c);
  199. }
  200.  
  201.